﻿Imports System.IO

Public Class FolderService

    Private fswCarpetas As FileSystemWatcher
    Private _carpeta As String

    Public Event RarListo(ByVal sender As Object, ByVal e As EventArgs)
    Public Event Dormir(ByVal sender As Object, ByVal e As EventArgs)
    Public ReadOnly Property Carpeta As String
        Get
            Return _carpeta
        End Get
    End Property

    Public Sub New()
    End Sub

    Public Sub Empezar()
        fswCarpetas = New FileSystemWatcher()
        Do While True
            fswCarpetas.Path = "C:\input"
            Dim result As WaitForChangedResult = fswCarpetas.WaitForChanged(WatcherChangeTypes.All)

            If result.Name = "finish-it" Then

                RmDir("C:\input" & "\" & "finish-it")

                
                _carpeta = "C:\input\subida.rar"
                RaiseEvent RarListo(Me, e:=New EventArgs)
            End If
            RaiseEvent Dormir(Me, e:=New EventArgs)
        Loop
    End Sub

    Protected Sub Cerrar()
        fswCarpetas.EnableRaisingEvents = False
    End Sub

    Public Sub WriteLog(ByVal mensaje As String)
        Dim ELog As New EventLog("killerbytes service", ".", "compresor")
        ELog.WriteEntry(mensaje)
        ELog.WriteEntry(mensaje, EventLogEntryType.Information, 234, CType(3, Short))
    End Sub
End Class
